tools lib traceevent: Fix use of uninitialized variables
authorBen Hutchings <ben@decadent.org.uk>
Sun, 20 Mar 2016 21:09:02 +0000 (21:09 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 27 Feb 2017 15:58:07 +0000 (15:58 +0000)
commitf33976725407a63c7dd14ecd8beba8bbab15fdff
treedb8d864e080da6a507d9d816163d82bc6346c249
parent2903460a8b5e2d40e235c644857bd7dfeee12584
tools lib traceevent: Fix use of uninitialized variables

Fix a number of correct warnings from gcc:

> plugin_function.c:133:6: warning: 'index' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   int index;
>       ^

'index' is initialized only if indentation is wanted.  Move the
printing of indentation using 'index' into the same if-statement.

> kbuffer-parse.c:339:27: warning: 'length' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   kbuf->next = kbuf->index + length;
>                            ^
> kbuffer-parse.c:297:15: note: 'length' was declared here
>   unsigned int length;
>                ^

'length' is not initialized when handling an OLD_RINGBUF_TYPE_TIME_EXTEND
record.  Based on what trace-cmd does, set length = 0 in this case.

> kbuffer-parse.c: In function 'kbuffer_read_at_offset':
> kbuffer-parse.c:632:9: warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   return data;
>          ^

'data' is not initialized if the offset is too small.  Initialize it
to NULL so that the behaviour is the same as when the offset is too
large.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name tools-lib-traceevent-fix-use-of-uninitialized-variables.patch
tools/lib/traceevent/kbuffer-parse.c
tools/lib/traceevent/plugin_function.c